* This code generates the main results (6 main tables in the paper) and Appendix tables
* "Beyond Home Bias: International Portfolio Holdings and Information Heterogeneity"
* by Filippo De Marco, Marco Macchiavelli, and Rosen Valchev


* the main data sets include:
* 	Consensus_EBA_final.dta (Tables 1, 3, 4, 5 and Appendix Tables)
* 	Consensu_EBA_extensive.dta (Table 6)
* 	Consensus_predictability.dta (Table 2)

*note that Consensus_EBA_final.dta Consensu_EBA_extensive.dta are pseudo-data, where the forecast variables have been replaced by zeros

****Table 2 Predictability
use Consensus_predictability,clear

*Y10_tg is the actual (tg=target) 10-year yield for country c in month m
*Y10_tg_lag3 is the lagged 10-year yield for country c in month m-3
*av_Y10_1 is the average forecast for country c made in month m-3 for Y10_tg

eststo clear
eststo: quietly reg Y10_tg  Y10_tg_lag3,   vce(robust )
test Y10_tg_lag3=1
eststo: quietly  reghdfe Y10_tg  Y10_tg_lag3 ,absorb( CountryID ) vce(robust )
test Y10_tg_lag3=1
eststo: quietly  reghdfe Y10_tg  Y10_tg_lag3 ,absorb( CountryID tm) vce(robust )
test Y10_tg_lag3=1
eststo: quietly reg Y10_tg  Y10_tg_lag3 av_Y10_1,  vce(robust )
test av_Y10_1=1
eststo: quietly  reghdfe Y10_tg  Y10_tg_lag3 av_Y10_1 ,absorb( CountryID ) vce(robust )
test av_Y10_1=1
eststo: quietly  reghdfe Y10_tg  Y10_tg_lag3 av_Y10_1 ,absorb( CountryID tm) vce(robust )
test av_Y10_1=1
 esttab ,   replace star(* 0.10 ** 0.05 *** 0.01) b(3) se(3) scalar(N r2 )

esttab using "Table2_predictability.tex", se r2 stat(N r2) nolines nogaps nomtitles noconst label b(%5.2f) se(%5.2f)  replace ///
prehead(\begin{table}\caption{Predictability of Sovereign Yields}\footnotesize\begin{center}\begin{tabular}{l*{6}{c}}\\ ///
&\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}&\multicolumn{1}{c}{(4)}&\multicolumn{1}{c}{(5)}&\multicolumn{2}{c}{(6)} \\ \hline) ///
 prefoot(\hline "Country FE &no&yes&yes&no&yes&yes\\" "Time FE &no&no&yes&no&no&yes\\" ) ///
postfoot(\hline\hline "\end{tabular} \end{center} \end{table}") starlevels("*" 0.10 "**" 0.05 "***" 0.01)alignment(D{.}{.}{-1}) page(dcolumn) nonumber




***Tables 1,3,4,5 and Appendix:

use Consensus_EBA_final,clear

** Table 1 Panel C
eststo clear
quietly estpost summarize  share_EEA_lt_mkt  SFE_Y10 FY10 l_dist, detail
esttab using "Table1_sumstats.tex", cells("mean(fmt(3)) sd(fmt(2)) p25(fmt(2)) p50(fmt(2)) p75(fmt(2)) p90(fmt(2))  p99(fmt(2)) count")  nonumber label title("Summary statistics") replace

** Table 3
eststo clear
quietly eststo : reg share_EEA_lt_mkt  l_dist , vce(cluster bankcountry)
quietly eststo : reghdfe share_EEA_lt_mkt  l_dist, absorb(ID  tq) cluster(bankcountry)
quietly eststo : reghdfe share_EEA_lt_mkt  l_dist, absorb(ID tq#CountryID)cluster(bankcountry)

quietly eststo : reg share_EEA_lt_mkt  l_dist SFE_Y10 FY10 SFE_Y10_FY10, vce(cluster bankcountry)
quietly eststo : reghdfe share_EEA_lt_mkt  l_dist SFE_Y10 FY10 SFE_Y10_FY10, absorb(ID  tq) cluster(bankcountry)
quietly eststo : reghdfe share_EEA_lt_mkt  l_dist SFE_Y10 FY10 SFE_Y10_FY10, absorb(ID tq#CountryID)cluster(bankcountry)

esttab using "Table3_InfoHeterog.tex", se r2 stat(N r2) nolines nogaps nomtitles noconst order(l_dist SFE_Y10 FY10 SFE_Y10_FY10) label b(%5.2f) se(%5.2f)  replace ///
prehead(\begin{table}\caption{Information Heterogeneity and Portfolio Holdings}  \footnotesize\begin{center}\begin{tabular}{l*{6}{c}} \\) ///
 prefoot(\hline "Bank FE &no&yes&yes&no&yes&yes \\" "Time FE &no&yes&-&no&yes&- \\" "Country-Time FE &no&no&yes&no&no&yes\\") ///
postfoot(\hline\hline "\end{tabular} \end{center} \end{table}") starlevels("*" 0.10 "**" 0.05 "***" 0.01)alignment(D{.}{.}{-1}) page(dcolumn) nonumber


** Table 4 ROBUSTNESS: Bank-time & Bank-Country FE, M&A
bysort ID: egen anyMA=max(crossborderMA)
tab ID if anyMA==1

label variable crossborderMA "$ CrossBorder M\&A _{bct}$"

eststo clear
quietly eststo : reghdfe share_EEA_lt_mkt l_dist SFE_Y10 FY10 SFE_Y10_FY10 , absorb(ID#tq tq#CountryID)cluster(bankcountry)
quietly eststo : reghdfe share_EEA_lt_mkt l_dist SFE_Y10 FY10 SFE_Y10_FY10 , absorb(ID#CountryID tq#CountryID)cluster(bankcountry)
quietly eststo : reghdfe share_EEA_lt_mkt l_dist SFE_Y10 FY10 SFE_Y10_FY10, absorb(ID#CountryID ID#tq tq#CountryID)cluster(bankcountry)
quietly eststo : reghdfe share_EEA_lt_mkt l_dist SFE_Y10 FY10 SFE_Y10_FY10 crossborderMA, absorb(ID tq#CountryID)cluster(bankcountry)
quietly eststo : reghdfe share_EEA_lt_mkt l_dist SFE_Y10 FY10 SFE_Y10_FY10 if anyMA==0, absorb(ID tq#CountryID)cluster(bankcountry)
quietly eststo : reghdfe share_EEA_lt_mkt l_dist SFE_Y10 FY10 SFE_Y10_FY10 crossborderMA, absorb(ID#CountryID ID#tq tq#CountryID)cluster(bankcountry)

esttab using "Table4_Robustness.tex", se r2 stat(N r2) nolines nogaps nomtitles noconst  order(SFE_Y10 FY10 SFE_Y10_FY10 crossborderMA) label b(%5.2f) se(%5.2f)  replace ///
prehead (\begin{table}\caption{Robustness}   ///
 \footnotesize\begin{center} \begin{tabular}{l*{6}{c}}\\&\multicolumn{3}{c}{Bank-Time, Bank-Country FE} &\multicolumn{3}{c}{Cross-border M\&A}\\ \cmidrule(lr){2-4}\cmidrule(lr){5-7} ///
 &\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)} &\multicolumn{1}{c}{(3)} &\multicolumn{1}{c}{(4)} &\multicolumn{1}{c}{(5)}&\multicolumn{1}{c}{(6)}\\ \hline  ) ///
 prefoot(\hline "Country-Time FE &yes&yes&yes&yes&yes&yes\\" "Bank FE &-&-&-&yes&yes&- \\" "Bank-Time FE &yes&no&yes&no&no&yes \\" "Bank-Country FE &no&yes&yes&no&no&yes\\") ///
postfoot(\hline "\end{tabular} \end{center} \end{table}") starlevels("*" 0.10 "**" 0.05 "***" 0.01)alignment(D{.}{.}{-1}) page(dcolumn) nonumber


** Table 5: IV-2SLS
eststo clear
*OLS
quietly eststo : reghdfe share_EEA_lt_mkt  l_dist  SFE_Y10 FY10 SFE_Y10_FY10  , absorb(ID tq#CountryID)cluster(bankcountry)
*1st stagea
quietly eststo : reghdfe FY10 foreignnonbank SFE_Y10_foreignnonbank l_dist SFE_Y10  , absorb(CountryID#tq ID ) cluster(bankcountry)
*1st stageb
quietly eststo : reghdfe SFE_Y10_FY10 foreignnonbank SFE_Y10_foreignnonbank l_dist SFE_Y10  , absorb(CountryID#tq ID ) cluster(bankcountry)
*2nd stage
quietly eststo : ivreghdfe share_EEA_lt_mkt l_dist SFE_Y10 (FY10 SFE_Y10_FY10 =  foreignnonbank SFE_Y10_foreignnonbank), absorb(CountryID#tq ID) cluster(bankcountry)

esttab, title("share_EEA_lt_mkt sample")  mlabels("c+tFE" "b+tFE""b+c+tFE""b+c*tFE" "c+tFE" "b+tFE""b+c+tFE""b+c*tFE")star(* 0.10 ** 0.05 *** 0.01) se(3) order(l_dist SFE_Y10 FY10 SFE_Y10_FY10) wrap compress stat(N r2 widstat)

esttab using "Table5_IV2SLS.tex", se r2 stat(N r2 idstat widstat F1stage) nolines nogaps nomtitles noconst order(l_dist SFE_Y10 FY10 SFE_Y10_FY10)  label b(%5.2f) se(%5.2f)  replace ///
prehead(\begin{table}\caption{Information Heterogeneity and Portfolio Holdings: Foreign non-bank IV}\\ ///
\footnotesize\begin{center}\begin{tabular}{l*{4}{c}}\\ &\multicolumn{1}{c}{OLS}&\multicolumn{2}{c}{1st stages}&\multicolumn{1}{c}{2nd stage}\\ ///
&&\multicolumn{1}{c}{Y10}&\multicolumn{1}{c}{ASFE$\times$ Y10}&\multicolumn{1}{c}{ShareEEA} \\ \hline ) ///
 prefoot(\hline "Bank FE &yes&yes&yes&yes \\" "Country-Time FE &yes&yes&yes&yes\\") ///
 postfoot(\hline\hline "\end{tabular} \end{center} \end{table}") starlevels("*" 0.10 "**" 0.05 "***" 0.01)alignment(D{.}{.}{-1}) page(dcolumn) nonumber

 
 ****APPENDIX TABLES
 
 
** Table A6
eststo clear
*OLS
quietly eststo : reghdfe share_EEA l_dist  SFE_Y10 FY10 SFE_Y10_FY10  , absorb(ID tq )cluster(bankcountry)
quietly eststo : reghdfe share_EEA  l_dist  SFE_Y10 FY10 SFE_Y10_FY10 , absorb(ID tq#CountryID)cluster(bankcountry)
*2nd stage
quietly eststo : ivreghdfe share_EEA l_dist  SFE_Y10 (FY10 SFE_Y10_FY10 =  foreignnonbank SFE_Y10_foreignnonbank), absorb(CountryID#tq ID) cluster(bankcountry)

esttab using "Tables_Appendix.tex", se r2 stat(N idstat widstat) nolines nogaps nomtitles noconst order(l_dist SFE_Y10 FY10 SFE_Y10_FY10) label b(%5.2f) se(%5.2f)  replace ///
prehead(\begin{table}\caption{Information Heterogeneity and Portfolio Holdings: Total Debt}\begin{footnotesize}  ***,**,* indicate statistical significance at 1\%, 5\%, and 10\%, respectively.\end{footnotesize}   ///
\footnotesize\begin{center}\begin{tabular}{l*{3}{c}}\\ &\multicolumn{2}{c}{OLS}&\multicolumn{1}{c}{IV-2SLS} \\ \hline ) ///
 prefoot(\hline "Bank FE &yes&yes&yes \\" "Country-Time FE &no&yes&yes\\") ///
postfoot(\hline\hline "\end{tabular} \end{center} \end{table}") starlevels("*" 0.10 "**" 0.05 "***" 0.01)alignment(D{.}{.}{-1}) page(dcolumn) nonumber



** Table A8: GIACOLETTI et al dispersion
eststo clear
quietly eststo : reg share_EEA_lt_mkt  l_dist dispersion FY10 dispersion_Y10 , vce(cluster bankcountry)
quietly eststo : reghdfe share_EEA_lt_mkt  l_dist dispersion FY10 dispersion_Y10, absorb(ID  tq) cluster(bankcountry)
quietly eststo : reghdfe share_EEA_lt_mkt  l_dist dispersion FY10 dispersion_Y10 , absorb(ID tq#CountryID)cluster(bankcountry)
esttab using "Tables_Appendix.tex", se r2 stat(N r2) nolines nogaps nomtitles noconst order(l_dist dispersion FY10 dispersion_Y10) label b(%5.2f) se(%5.2f)  append ///
prehead(\begin{table}\caption{Foreign Portfolios and Forecast Dispersion (Giacoletti et al., 2021).}  \footnotesize\begin{center}\begin{tabular}{l*{3}{c}}\\  ///
&\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)} \\ \hline ) ///
 prefoot(\hline "Bank FE &no&yes&yes\\" "Country-Time FE &no&yes&-" "Time FE &no&yes&- \\" "Country-Time FE &no&no&yes\\") ///
postfoot(\hline\hline "\end{tabular} \end{center} \end{table}") starlevels("*" 0.10 "**" 0.05 "***" 0.01)alignment(D{.}{.}{-1}) page(dcolumn) nonumber




** Table A7: Bootstrap

**col (1) no FE
cap program drop myboot
program define myboot, rclass
use Consensus_EBA_final,clear
bsample
reghdfe share_EEA_lt_mkt l_dist SFE_Y10 FY10 SFE_Y10_FY10,noabsorb
matrix coeff=e(b)
return scalar coeff1=coeff[1,1]
return scalar coeff2=coeff[1,2]
return scalar coeff3=coeff[1,3]
return scalar coeff4=coeff[1,4]
end

simulate coeff1=coeff[1,1] coeff2=coeff[1,2] coeff3=coeff[1,3] coeff4=coeff[1,4], reps(1000) : myboot
summ coeff*

forval i=1(1)4{
sum coeff`i'
scalar se`i'=r(sd)
}


*col (2) Bank+Tme FE
cap program drop myboot
program define myboot, rclass
use Consensus_EBA_final,clear
bsample
reghdfe share_EEA_lt_mkt l_dist SFE_Y10 FY10 SFE_Y10_FY10, absorb(ID tq)
matrix coeff=e(b)
return scalar coeff1=coeff[1,1]
return scalar coeff2=coeff[1,2]
return scalar coeff3=coeff[1,3]
return scalar coeff4=coeff[1,4]
end

simulate coeff1=coeff[1,1] coeff2=coeff[1,2] coeff3=coeff[1,3] coeff4=coeff[1,4], reps(1000) : myboot
summ coeff*

forval i=1(1)4{
sum coeff`i'
scalar se`i'=r(sd)
}



*col (3) Bank+country*time FE
cap program drop myboot
program define myboot, rclass
use Consensus_EBA_final,clear
bsample
reghdfe share_EEA_lt_mkt l_dist SFE_Y10 FY10 SFE_Y10_FY1, absorb(ID CountryID#tq)
matrix coeff=e(b)
return scalar coeff1=coeff[1,1]
return scalar coeff2=coeff[1,2]
return scalar coeff3=coeff[1,3]
return scalar coeff4=coeff[1,4]
end

simulate coeff1=coeff[1,1] coeff2=coeff[1,2] coeff3=coeff[1,3] coeff4=coeff[1,4], reps(1000) : myboot
summ coeff*

forval i=1(1)4{
sum coeff`i'
scalar se`i'=r(sd)
}




**Table A9:
use Consensus_EBA_Home_final,clear

eststo clear
quietly eststo : reg share_EEA_lt_mkt l_dist , vce(cluster bankcountry)
quietly eststo : reghdfe share_EEA_lt_mkt l_dist , absorb(ID  tq) cluster(bankcountry)
quietly eststo : reghdfe share_EEA_lt_mkt l_dist , absorb(ID tq#CountryID)cluster(bankcountry)

quietly eststo : reg share_EEA_lt_mkt Home l_dist SFE_Y10 FY10 SFE_Y10_FY10, vce(cluster bankcountry)
quietly eststo : reghdfe share_EEA_lt_mkt Home l_dist SFE_Y10 FY10 SFE_Y10_FY10, absorb(ID  tq) cluster(bankcountry)
quietly eststo : reghdfe share_EEA_lt_mkt Home l_dist SFE_Y10 FY10 SFE_Y10_FY10, absorb(ID tq#CountryID)cluster(bankcountry)
esttab using "Tables_Appendix.tex", se r2 stat(N r2) nolines nogaps nomtitles noconst order(l_dist Home SFE_Y10 FY10 SFE_Y10_FY10) label b(%5.2f) se(%5.2f)  append ///
prehead(\begin{table}\caption{Information Heterogeneity and Portfolio Holdings: Domestic Debt} \footnotesize\begin{center}\begin{tabular}{l*{6}{c}}\\ &\multicolumn{1}{c}{OLS}&\multicolumn{2}{c}{1st stages}&\multicolumn{1}{c}{2nd stage}&\multicolumn{1}{c}{OLS}&\multicolumn{1}{c}{1st stage}&\multicolumn{1}{c}{2nd stage}\\ ///
&\multicolumn{1}{c}{ShareEEA}&\multicolumn{1}{c}{Y10}&\multicolumn{1}{c}{ASFE$\times$ Y10}&\multicolumn{1}{c}{ShareEEA}&\multicolumn{1}{c}{ShareEEA}&\multicolumn{1}{c}{ASFE$\times$ Y10}&\multicolumn{1}{c}{ShareEEA} \\ \hline ) ///
 prefoot(\hline "Bank FE &no&yes&yes&no&yes&yes \\" "Time FE &no&yes&-&no&yes&- \\" "Country-Time FE &no&no&yes&no&no&yes\\") ///
postfoot(\hline\hline "\end{tabular} \end{center} \end{table}") starlevels("*" 0.10 "**" 0.05 "***" 0.01)alignment(D{.}{.}{-1}) page(dcolumn) nonumber



 
 
 

 
 *Table 6: Sparseness in Foreign Portfolios and Forecasts
 use EBA_sparseness,clear
 
 **Table 1 Panel A Summary Statistics
eststo clear
estpost summarize share_EEA_lt_mkt pos_EEA ForeignFcst, detail
esttab using "Table1_sumstats.tex", cells("mean(fmt(3)) sd(fmt(2)) p25(fmt(2)) p50(fmt(2)) p75(fmt(2)) p90(fmt(2))  p99(fmt(2)) count")  nonumber label title("Summary statistics") append


  eststo clear								
quietly eststo : reg share_EEA_lt_mkt l_dist  , vce(cluster bankcountry)
quietly eststo : reghdfe share_EEA_lt_mkt l_dist  , absorb(ID tm)  cluster(bankcountry) 
quietly eststo : reghdfe share_EEA_lt_mkt l_dist  , absorb(ID cym) cluster(bankcountry) 
quietly eststo : reghdfe share_EEA_lt_mkt l_dist  , absorb(bym cym) cluster(bankcountry) 		
quietly eststo : reghdfe share_EEA_lt_mkt l_dist  ForeignFcst, noabsorb cluster(bankcountry)
quietly eststo : reghdfe share_EEA_lt_mkt l_dist  ForeignFcst, absorb(ID tm)  cluster(bankcountry) 
quietly eststo : reghdfe share_EEA_lt_mkt l_dist  ForeignFcst, absorb(ID cym) cluster(bankcountry) 
quietly eststo : reghdfe share_EEA_lt_mkt l_dist  ForeignFcst, absorb(bym cym) cluster(bankcountry) 		

 esttab using "Table6_sparseness.tex", se r2 keep(l_dist  ForeignFcst) nolines nogaps nomtitles noconst label b(%5.3f) se(%5.3f) order(l_dist ForeignFcst) replace ///
prehead(\begin{table}\caption{Extensive Margin: Foreign Sovereign Exposures and Foreign Forecast} ///
\small\begin{center}\begin{tabular}{l*{8}{c}}\\ &\multicolumn{8}{c}{Panel A: Dependent variable ShareSovEEA}\\ \hline ) ///
 prefoot(\hline) ///
postfoot(\hline "\end{tabular} \end{center} ") starlevels("*" 0.10 "**" 0.05 "***" 0.01)alignment(D{.}{.}{-1}) page(dcolumn) nonumber

  
   eststo clear								
quietly eststo : reg pos_EEA l_dist  , vce(cluster bankcountry)
quietly eststo : reghdfe pos_EEA l_dist  , absorb(ID tm)  cluster(bankcountry) 
quietly eststo : reghdfe pos_EEA l_dist  , absorb(ID cym) cluster(bankcountry) 
quietly eststo : reghdfe pos_EEA l_dist  , absorb(bym cym) cluster(bankcountry) 		
quietly eststo : reghdfe pos_EEA l_dist  ForeignFcst, noabsorb cluster(bankcountry)
quietly eststo : reghdfe pos_EEA l_dist  ForeignFcst, absorb(ID tm)  cluster(bankcountry) 
quietly eststo : reghdfe pos_EEA l_dist  ForeignFcst, absorb(ID cym) cluster(bankcountry) 
quietly eststo : reghdfe pos_EEA l_dist  ForeignFcst, absorb(bym cym) cluster(bankcountry) 		

 esttab using "Table6_sparseness.tex", se r2 keep(l_dist  ForeignFcst) nolines nogaps nomtitles noconst label b(%5.2f) se(%5.2f) order(l_dist ForeignFcst) append ///
prehead(\small\begin{center}\begin{tabular}{l*{8}{c}}\\ &\multicolumn{8}{c}{Panel B: Dependent variable 100$\times$1(ShareSovEEA) }\\ \hline ) ///
 prefoot(\hline "Time FE &no&yes&--&-- &no&yes&--&-- \\" "Bank FE &no&yes&yes&-- &no&yes&yes&--\\" "Country-Time FE &no&no&yes&yes &no&no&yes&yes\\" "Bank-Time FE &no&no&no&yes &no&no&no&yes\\") ///
postfoot(\hline\hline "\end{tabular} \end{center} \end{table}") starlevels("*" 0.10 "**" 0.05 "***" 0.01)alignment(D{.}{.}{-1}) page(dcolumn) nonumber



 

